/* 
 * gtkn4.c
 *  
 */
#include <gdk/gdk.h>
#include <gtk/gtk.h>

void destroy(void) {
  gtk_main_quit();
}

int main (int argc, char** argv) {
  gtk_init (&argc, &argv);

  GdkVisual* gdkvisual = gdk_visual_get_system();
  gint width  = 100;
  gint height = 100;
  GdkImage* gdkimage = gdk_image_new(GDK_IMAGE_NORMAL, 
					gdkvisual,
					width, height );
  if (gdkimage == NULL ) {
     fprintf( stderr, "Not able to create gdkimage object\n");
     return -1;
  }
  fprintf( stdout, "Bits per pixel: %d\n",  gdkimage->bits_per_pixel );

  GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GtkWidget* image  = gtk_image_new_from_image( gdkimage, NULL );
  
  /*
   * draw pixels in the gdkimage object
   */
  gint i;
  for (i=0; i<width; i++){
    gint j;
    for (j=0; j<height; j++){
       guint32 pixel = i + j;
       gdk_image_put_pixel( gdkimage, i, j, pixel);
    }
  }
  gtk_signal_connect(GTK_OBJECT (window), "destroy",
             GTK_SIGNAL_FUNC (destroy), NULL);

  gtk_container_add(GTK_CONTAINER (window), image);

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}
